﻿
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;


namespace FarseerGames.AdvancedSamples.Demos.DemoShare
{

    class XNA2dCamera
    {
        /*
        private SpriteBatch spriteRenderer;
        private Vector2 cameraPosition;

        public Vector2 Position
        {
            get { return cameraPosition; }
            set { cameraPosition = value; }
        }

        public Camera2D(SpriteBatch renderer)
        {
        spriteRenderer = renderer;
        cameraPosition = new Vector2(0, 0);
        }

        public void DrawNode(Scene2DNode node)
        {
        // get the screen position of the node
        Vector2 drawPosition = ApplyTransformations(node.Position);
        node.Draw(spriteRenderer, drawPosition);
        }

        private Vector2 ApplyTransformations(Vector2 nodePosition)
        {
        // apply translation - zoom can be applied here
        Vector2 finalPosition = nodePosition - cameraPosition;
        return finalPosition;
        }
        public void Translate(Vector2 moveVector)
        {
        cameraPosition += moveVector;
        }
         * */

        
        #region Variables
        Vector2 _position;

        #endregion Variables

        #region Constructor

        public XNA2dCamera()
        {
            _position = new Vector2 ();
        }

        public XNA2dCamera(Vector2 i_pos)
        {
            _position = i_pos;
        }

        #endregion Constructor

        #region Camera Transformation Methods

        public void translation(Vector2 t_vector)
        {
            _position += t_vector;
        }

        #endregion Camera Transformation Methods

        #region Sprite Drawing

        public Vector2 actualRenderPosition(Vector2 sprite_position)
        {
            Vector2 final_pos = sprite_position - _position;

            return final_pos;
        }
        #endregion Sprite Drawing
         
    }

}


/*
         * 
         * The following code requires System.Drawing.dll
      
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Drawing;

    public class XNA2dCamera 
    {
        #region Properties and Fields
        #region Position

        #region Constructors
        public XNA2dCamera()
        {
            visibleArea = new RectangleF(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
            position = ScreenPosition;
        }
        public XNA2dCamera(float width, float height)
        {
            visibleArea = new RectangleF(0, 0, width, height);
            position = ScreenPosition;
        }
        public XNA2dCamera(float x, float y, float width, float height)
        {
            visibleArea = new RectangleF(x - (width / 2), y - (height / 2), width, height);
            position.X = x;
            position.Y = y;
        }
        #endregion Constructors

        protected Vector2 position = Vector2.Zero;
        public Vector2 Position
        {
            get { return position; }
            set
            {
                position = value;
                visibleArea.Left = position.X + offset.X - visibleArea.Width / 2;
                visibleArea.Top = position.Y + offset.Y - visibleArea.Height / 2;
            }
        }

        protected Vector2 offset = Vector2.Zero;
        public Vector2 Offset
        {
            get { return offset; }
            set
            {
                offset = value;
                visibleArea.Left = position.X + offset.X - visibleArea.Width / 2;
                visibleArea.Top = position.Y + offset.Y - visibleArea.Height / 2;
            }
        }
        #endregion Position

        #region Culling

        // Using floats due to accuracy stuff
        protected RectangleF visibleArea;

        public RectangleF VisibleArea
        {
           get { return visibleArea; }
        }

        public float ViewingWidth
        {
            get { return visibleArea.Width; }
            set { visibleArea.Width = value; }
        }

        public float ViewingHeight
        {
            get { return visibleArea.Height; }
            set { visibleArea.Height = value; }
        }
        #endregion Culling

        #region Transformations
        protected float rotation = 0.0f;
        public float Rotation
        {
            get { return rotation; }
            set { rotation = value; }
        }

        // <0 - <1 = Zoom Out
        // >1 = Zoom In
        // <0 = Funky (flips axis, dont try if unsure, or u will get weird results)
        protected Vector2 zoom = Vector2.One;
        public Vector2 Zoom
        {
            get { return zoom; }
            set { zoom = value; }
        }
        #endregion Transformations

        public Vector2 ScreenPosition
        {
            get { return new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2); }
        }
        #endregion Properties and Fields

        #region Destructors
        public void Dispose()
        {
            visibleArea = null;

            // Clear out event handlers
            PositionChanged = null;
            Teleported = null;
            Moved = null;
        }
        #endregion

        #region Methods

        // Use the methods here to change the offset position of the camera to where we want it to be

        public virtual Matrix ViewTransformationMatrix()
        {
            Vector3 matrixRotOrigin = new Vector3(Position + Offset, 0);
            Vector3 matrixScreenPos = new Vector3(ScreenPosition, 0.0f);

            // Translate back to the origin based on the camera’s offset position, since we’re rotating around the camera
            // Then, we scale and rotate around the origin
            // Finally, we translate to SCREEN coordinates, so translation is based on the ScreenCenter

            return Matrix.CreateTranslation(-matrixRotOrigin) *
                Matrix.CreateScale(ActiveCamera.Zoom.X, ActiveCamera.Zoom.Y, 1.0f) *
                Matrix.CreateRotationZ(ActiveCamera.Rotation) *
                Matrix.CreateTranslation(matrixScreenPos);
        }
        #endregion Methods
    }
*/

